

package com.hazelcast.internal.serialization.impl.defaultserializers;

import com.hazelcast.internal.serialization.impl.SerializationConstants;
import com.hazelcast.internal.util.SetUtil;
import com.hazelcast.nio.ObjectDataInput;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

/**
 * The {@link HashSet} serializer
 * <p>
 * Important Note: The HashSet 'loadfactor' is not serialized.
 */
public class HashSetStreamSerializer<E> extends AbstractCollectionStreamSerializer<Set<E>> {

    @Override
    public int getTypeId() {
        return SerializationConstants.JAVA_DEFAULT_TYPE_HASH_SET;
    }

    @Override
    public Set<E> read(ObjectDataInput in) throws IOException {
        int size = in.readInt();

        Set<E> collection = SetUtil.createHashSet(size);

        return deserializeEntries(in, size, collection);
    }
}
